package org.goodev.arch.vm;

import android.arch.lifecycle.LifecycleActivity;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.widget.TextView;

import org.goodev.arch.R;

public class ViewModelActivity extends LifecycleActivity {
    TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_model);
        mTextView = (TextView) findViewById(R.id.text);

        UserViewModel vm = ViewModelProviders.of(this).get(UserViewModel.class);
        vm.getUser().observe(this, user -> {
            mTextView.setText(user.body.toString());
        });

        vm.setUser("goodev");
    }
}
